home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 …ember: Reference Library / Dev.CD Dec 00 RL Disk 1.toast / pc / technical documentation / develop / develop issue 26 / develop issue 26 code / som and listpart / listpart dr4 / source / listpartlist.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1995-12-11  |  33.5 KB  |  1,306 lines

  1.  
  2. #if 0
  3.     #define     WeBeHere(StringPtr) DebugStr(StringPtr)
  4. #else
  5.     #define     WeBeHere(StringPtr)
  6. #endif
  7.  
  8. #ifndef _COMPILERDEFS_
  9. #include "CompDefs.h"
  10. #endif
  11.  
  12. #ifndef __DEBUGTOOLS__
  13. #include "DebugTools.h"
  14. #endif
  15.  
  16. // -- OpenDoc Utilities --
  17.  
  18. #ifndef _EXCEPT_
  19. // Exceptions define several important macros (ie. CHECKENV)
  20. // which are used in the SOM method dispatch glue. If Except.h
  21. // is not included early enough, exceptions may not be thrown
  22. // correctly when returning from a SOM method with the "ev" parameter set.
  23. #include <Except.h>
  24. #endif
  25.  
  26. // --- ListPart Includes ---
  27.  
  28. #ifndef _LISTPART_
  29. #include "ListPart.h"
  30. #endif
  31.  
  32. #ifndef _LISTPARTGLOBALS_
  33. #include "ListPartGlobals.h"
  34. #endif
  35.  
  36. #ifndef _LISTPARTUTILS_
  37. #include "ListPartUtils.h"
  38. #endif
  39.  
  40. #ifndef _LISTPARTDEF_
  41. #include "ListPartDef.h"
  42. #endif
  43.  
  44. // --- OpenDoc Includes ---
  45.  
  46. #ifndef _ODTYPES_
  47. #include <ODTypes.h>
  48. #endif
  49.  
  50. #ifndef SOM_ODDispatcher_xh
  51. #include <Disptch.xh>
  52. #endif
  53.  
  54. #ifndef SOM_ODFrameFacetIterator_xh
  55. #include <FrFaItr.xh>
  56. #endif
  57.  
  58. #ifndef SOM_Module_OpenDoc_StdProps_defined
  59. #include <StdProps.xh>
  60. #endif
  61.  
  62. #ifndef SOM_Module_OpenDoc_StdTypes_defined
  63. #include <StdTypes.xh>
  64. #endif
  65.  
  66. #ifndef SOM_Module_OpenDoc_StdDefs_defined
  67. #include <StdDefs.xh>
  68. #endif
  69.  
  70. #ifndef SOM_ODFrame_xh
  71. #include <Frame.xh>
  72. #endif
  73.  
  74. #ifndef SOM_ODSession_xh
  75. #include <ODSessn.xh>
  76. #endif
  77.  
  78. #ifndef SOM_ODDraft_xh
  79. #include <Draft.xh>
  80. #endif
  81.  
  82. #ifndef SOM_ODStorageUnit_xh
  83. #include <StorageU.xh>
  84. #endif
  85.  
  86. #ifndef SOM_ODStorageUnitView_xh
  87. #include <SUView.xh>
  88. #endif
  89.  
  90. #ifndef SOM_ODDocument_xh
  91. #include <Document.xh>
  92. #endif
  93.  
  94. #ifndef SOM_ODContainer_xh
  95. #include <ODCtr.xh>
  96. #endif
  97.  
  98. #ifndef SOM_ODNameSpaceManager_xh
  99. #include <NmSpcMg.xh>
  100. #endif
  101.  
  102. #ifndef SOM_ODValueNameSpace_xh
  103. #include <ValueNS.xh>
  104. #endif
  105.  
  106. // -- OpenDoc Utilities --
  107.  
  108. #ifndef _FOCUSLIB_
  109. #include <FocusLib.h>
  110. #endif
  111.  
  112. #ifndef _BNDNSUTL_
  113. #include <BndNSUtl.h>
  114. #endif
  115.  
  116. #ifndef _DOCUTILS_
  117. #include <DocUtils.h>
  118. #endif
  119.  
  120. #ifndef _ISOSTR_
  121. #include <ISOStr.h>
  122. #endif
  123.  
  124. #ifndef _ODDEBUG_
  125. #include <ODDebug.h>
  126. #endif
  127.  
  128. #ifndef _STDTYPIO_
  129. #include <StdTypIO.h>
  130. #endif
  131.  
  132. #ifndef _STORUTIL_    
  133. #include <StorUtil.h>
  134. #endif
  135.  
  136. #ifndef _TEMPOBJ_
  137. #include <TempObj.h>
  138. #endif
  139.  
  140. #ifndef _TEMPITER_
  141. #include <TempIter.h>
  142. #endif
  143.  
  144. #ifndef _USERSRCM_
  145. #include <UseRsrcM.h>
  146. #endif
  147.  
  148. // --- Macintosh Includes ---
  149.  
  150. #ifndef __RESOURCES__
  151. #include <Resources.h>
  152. #endif
  153.  
  154. #ifndef __GXMATH__
  155. #include <GXMath.h>
  156. #endif
  157.  
  158. #ifndef __SCRIPT__
  159. #include <Script.h>
  160. #endif
  161.  
  162. #ifndef __TEXTUTILS__
  163. #include <TextUtils.h>
  164. #endif
  165.  
  166. /*
  167. #ifndef _ALTPOINT_
  168. #include <AltPoint.h>
  169. #endif
  170.  
  171. #ifndef __DEBUGTOOLS__
  172. #include "DebugTools.h"
  173. #endif
  174.  
  175. #ifndef _LISTPART_
  176. #include "CPListPart.h"
  177. #endif
  178.  
  179. #ifndef _PARTUTILS_
  180. #include "PartUtils.h"
  181. #endif
  182.  
  183. #ifndef _LISTPARTDEF_
  184. #include "ListPartDef.h"
  185. #endif
  186.  
  187. #ifndef _USERSRCM_
  188. #include <UseRsrcM.h>
  189. #endif
  190.  
  191. #ifndef _INFOUTIL_
  192. #include <InfoUtil.h>
  193. #endif
  194.  
  195. #ifndef _ITEXT_
  196. #include <IText.h>
  197. #endif
  198.  
  199. #ifndef SOM_ODDispatcher_xh
  200. #include <Disptch.xh>
  201. #endif
  202.  
  203. #ifndef SOM_ODDraft_xh
  204. #include <Draft.xh>
  205. #endif
  206.  
  207. #ifndef SOM_ODArbitrator_xh
  208. #include <Arbitrat.xh>
  209. #endif
  210.  
  211. #ifndef SOM_ODCanvas_xh
  212. #include <Canvas.xh>
  213. #endif
  214.  
  215. #ifndef SOM_ODPart_xh
  216. #include <Part.xh>
  217. #endif
  218.  
  219. #ifndef SOM_ODFacet_xh
  220. #include <Facet.xh>
  221. #endif
  222.  
  223. #ifndef SOM_ODFrame_xh
  224. #include <Frame.xh>
  225. #endif
  226.  
  227. #ifndef SOM_ODFrameFacetIterator_xh
  228. #include <FrFaItr.xh>
  229. #endif
  230.  
  231. #ifndef SOM_ODFoci_xh
  232. #include <Foci.xh>
  233. #endif
  234.  
  235. #ifndef SOM_ODInfo_xh
  236. #include <Info.xh>
  237. #endif
  238.  
  239. #ifndef SOM_ODPstObj_
  240. #include <PstObj.xh>
  241. #endif
  242.  
  243. #ifndef SOM_ODShape_xh
  244. #include <Shape.xh>
  245. #endif
  246.  
  247. #ifndef SOM_ODStdProps_xh
  248. #include <StdProps.xh>
  249. #endif
  250.  
  251. #ifndef SOM_ODStdTypes_xh
  252. #include <StdTypes.xh>
  253. #endif
  254.  
  255. #ifndef _STDDEFS_
  256. #include <StdDefs.xh>
  257. #endif
  258.  
  259. #ifndef _PLFMDEF_
  260. #include <PlfmDef.h>
  261. #endif
  262.  
  263. #ifndef SOM_ODCmdDefs_xh
  264. #include <CmdDefs.xh>
  265. #endif
  266.  
  267. #ifndef SOM_ODStorageU_xh
  268. #include <StorageU.xh>
  269. #endif
  270.  
  271. #ifndef SOM_ODTrnsform_xh
  272. #include <Trnsform.xh>
  273. #endif
  274.  
  275. #ifndef SOM_ODFocusSet_xh
  276. #include <FocusSet.xh>
  277. #endif
  278.  
  279. #ifndef SOM_ODFoci_xh
  280. #include <Foci.xh>
  281. #endif
  282.  
  283. #ifndef SOM_ODMenuBar_xh
  284. #include <MenuBar.xh>
  285. #endif
  286.  
  287. #ifndef SOM_ODWindow_xh
  288. #include <Window.xh>
  289. #endif
  290.  
  291. #ifndef SOM_ODWinStat_xh
  292. #include <WinStat.xh>
  293. #endif
  294.  
  295. #ifndef SOM_ODSession_xh
  296. #include <ODSessn.xh>
  297. #endif
  298.  
  299. #ifndef _PASCLSTR_
  300. #include <PasclStr.h>
  301. #endif
  302.  
  303. #ifndef _FOCUSLIB_
  304. #include <FocusLib.h>
  305. #endif
  306.  
  307. #ifndef __ERRORS__
  308. #include <Errors.h>
  309. #endif
  310.  
  311. #ifndef __RESOURCES__
  312. #include <Resources.h>
  313. #endif
  314.  
  315. #ifndef __DIALOGS__
  316. #include <Dialogs.h>
  317. #endif
  318.  
  319. #ifndef __TOOLUTILS__
  320. #include <ToolUtils.h>
  321. #endif
  322.  
  323. #ifndef _STORUTIL_
  324. #include <StorUtil.h>
  325. #endif
  326. */
  327.  
  328. //====================================================================
  329. // Miscellaneous
  330. //====================================================================
  331.  
  332.  
  333. #ifdef applec
  334. #pragma segment ListPartList
  335. #endif
  336.  
  337. pascal void ControlThumbAction(void);
  338. pascal void ControlThumbAction(void)
  339.     {
  340.     ((ListPart *)gMySelf)->TheControlThumbAction(gEv, gFacet, gControl);
  341.     }
  342.  
  343. pascal void ControlAction(ControlHandle theControl, short thePart);
  344. pascal void ControlAction(ControlHandle theControl, short thePart)
  345.     {
  346.     ((ListPart *)gMySelf)->TheControlAction(gEv, gFacet, theControl, thePart);
  347.     }
  348.  
  349. void UtilSetControlValue(ControlHandle theControl, short theValue);
  350. void UtilSetControlValue(ControlHandle theControl, short theValue)
  351.     {
  352.         GrafPtr    curPort;
  353.         ::GetPort(&curPort);
  354.         Rect r = curPort->portRect;
  355.         short dh = -r.left;
  356.         short dv = -r.top;
  357.         ::SetOrigin(0, 0);
  358.         ::OffsetRgn(curPort->clipRgn, dh, dv);
  359.         ::SetControlValue(theControl, theValue);
  360.         ::OffsetRgn(curPort->clipRgn, -dh, -dv);
  361.         ::SetOrigin(-dh, -dv);
  362.     }
  363.  
  364. void ListPart::TheControlAction(Environment* ev, ODFacet* theFacet, ControlHandle theControl, short thePart)
  365.     {
  366.     short oldVal = ::GetControlValue(theControl);
  367.     short theMin = ::GetControlMinimum(theControl);
  368.     short theMax = ::GetControlMaximum(theControl);
  369.     ListFacetInfoPtr lfip = (ListFacetInfoPtr)theFacet->GetPartInfo(ev);
  370.     short locNbVis = lfip->fNbVis;
  371.     short newVal = oldVal;
  372.     switch (thePart)
  373.         {
  374.         case kControlUpButtonPart: if (oldVal > theMin) newVal = oldVal-1; break;
  375.         case kControlDownButtonPart: if (oldVal < theMax) newVal = oldVal+1; break;
  376.         case kControlPageUpPart: if (oldVal > theMin) newVal = oldVal-locNbVis+1; break;
  377.         case kControlPageDownPart: if (oldVal < theMax) newVal = oldVal+locNbVis-1; break;
  378.         }
  379.     ::SetControlValue(theControl, newVal);
  380.     newVal = ::GetControlValue(theControl);
  381.     if (oldVal != newVal) ScrollTo(ev, theFacet, newVal);
  382.     }
  383.  
  384. void ListPart::TheControlThumbAction(Environment* ev, ODFacet* theFacet, ControlHandle theControl)
  385.     {
  386.     Point localPt;
  387.     long mytmin, myval, ctlmin, ctlmax, rtop, rleft, rbottom, rright;
  388.     Boolean insideArea;
  389.  
  390.     rtop = (*theControl)->contrlRect.top;
  391.     rleft = (*theControl)->contrlRect.left;
  392.     rbottom = (*theControl)->contrlRect.bottom;
  393.     rright = (*theControl)->contrlRect.right;
  394.     ::GetMouse(&localPt);
  395.     mytmin = localPt.v - gInitDelta;
  396.     ctlmin = (*theControl)->contrlMin;
  397.     ctlmax = (*theControl)->contrlMax;
  398.     myval = (((mytmin-rtop-16)*(ctlmax-ctlmin)*100) / (rbottom-48-rtop))+50;
  399.     myval = ctlmin + (myval / 100);
  400.     if (myval < ctlmin) myval = ctlmin;
  401.     if (myval > ctlmax) myval = ctlmax;
  402.     insideArea = ((localPt.h <= rright + 23) && (localPt.h >= rleft - 24));
  403.     if (insideArea && (gTempoVal != myval))
  404.         {
  405.         PenState thePnState;
  406.         ::GetPenState(&thePnState);
  407.         PenNormal();
  408.         gTempoVal = myval;
  409.         mytmin = (*theControl)->contrlValue;
  410.         (*theControl)->contrlValue = myval;
  411.         ScrollTo(ev, theFacet, myval);
  412.         (*theControl)->contrlValue = mytmin;
  413.         ::SetPenState(&thePnState);
  414.         }
  415.     }
  416.  
  417. void ListPart::HandleMouseDownInList(Environment* ev, ODEventData* event, ODFacet* facet, Point macPoint)
  418.     {
  419.     WeBeHere("\pListPart::HandleMouseDownInList");
  420.     CFocus foc(ev, facet);
  421.  
  422.     short ctlPart, oldValue, newValue, scrollThumbOk = 0;
  423.     ControlActionUPP myRoutine;
  424.     ListFacetInfoPtr lfip = (ListFacetInfoPtr)facet->GetPartInfo(ev);
  425.     ControlHandle aCtl = lfip->fListCtl;
  426.  
  427.     if (aCtl)
  428.         {
  429.         gMySelf = (ODPart *)this;
  430.         gControl = aCtl;
  431.         gEv = ev;
  432.         gFacet = facet;
  433.         oldValue = ::GetControlValue(aCtl);
  434.  
  435.         GrafPtr    curPort;
  436.         ::GetPort(&curPort);
  437.         Rect r = curPort->portRect;
  438.         short dh = -r.left;
  439.         short dv = -r.top;
  440.         SetOrigin(0, 0);
  441.         OffsetRgn(curPort->clipRgn, dh, dv);
  442.         macPoint.h += dh;
  443.         macPoint.v += dv;
  444.  
  445.         if ((ctlPart = ::TestControl(aCtl, macPoint)) != 0)
  446.             {
  447.             if (fKind == kActive) if (fLineOpened) CloseCellOpened(ev);
  448.             switch (ctlPart)
  449.                 {
  450.                 case kControlIndicatorPart :
  451.                     if (fAutoThumb)
  452.                         {
  453.                         gTempoVal = ::GetControlValue(aCtl);
  454.                         gInitDelta = macPoint.v - (*((RgnHandle)((*aCtl)->contrlData)))->rgnBBox.top;
  455.                         myRoutine = (ControlActionUPP)NewRoutineDescriptor((ProcPtr)ControlThumbAction, kPascalStackBased, kPowerPCISA);
  456.                         if (::TrackControl(aCtl, macPoint, myRoutine) == kControlIndicatorPart) scrollThumbOk = 1;
  457.                         if (gTempoVal != ::GetControlValue(aCtl)) scrollThumbOk = 0;
  458.                         DisposeRoutineDescriptor(myRoutine);
  459.                         }
  460.                     else if (::TrackControl(aCtl, macPoint, (ControlActionUPP)-1L) != kControlIndicatorPart) scrollThumbOk = 1;
  461.                     if (scrollThumbOk == 0) ScrollTo(ev, facet, ::GetControlValue(aCtl));
  462.                     break;
  463.                 case kControlUpButtonPart:
  464.                 case kControlDownButtonPart:
  465.                 case kControlPageUpPart:
  466.                 case kControlPageDownPart:
  467.                     myRoutine = NewControlActionProc(ControlAction);
  468.                     do ::TrackControl(aCtl, macPoint, myRoutine); while (::StillDown());
  469.                     DisposeRoutineDescriptor(myRoutine);
  470.                     break;
  471.                 }
  472.             }
  473.  
  474.         OffsetRgn(curPort->clipRgn, -dh, -dv);
  475.         SetOrigin(-dh, -dv);
  476.         macPoint.h -= dh;
  477.         macPoint.v -= dv;
  478.  
  479.         Rect bounds = lfip->fUsedRect;
  480.         bounds.right -= 18;
  481.         bounds.top += 3;
  482.         bounds.left += 3;
  483.         bounds.bottom -= 3;
  484.         short where;
  485.         char val;
  486.         gTempoVal = 0;
  487.         if (::PtInRect(macPoint, &bounds))
  488.             if (FirstClick(ev, facet, event, &where, &val, macPoint))
  489.                 while (::StillDown()) StillClick(ev, facet, where, val);
  490.         
  491.         if ((oldValue != (newValue = ::GetControlValue(aCtl))) || (gTempoVal != 0))
  492.             {
  493.             CListIterator fiter(fDisplayFrames);
  494.             for ( CFrameProxy* proxy = (CFrameProxy*) fiter.First();
  495.                     fiter.IsNotComplete(); proxy = (CFrameProxy*) fiter.Next() )
  496.                 {
  497.                 ODFrameFacetIterator* facets = proxy->GetFrame(ev)->CreateFacetIterator(ev);
  498.                 for (ODFacet* fct = facets->First(ev);
  499.                         facets->IsNotComplete(ev);
  500.                         fct = facets->Next(ev) )
  501.                     {
  502.                     if (fct != facet)
  503.                         {
  504.                         CFocus lfoc(ev, fct);
  505.                         ListFacetInfoPtr lfip = (ListFacetInfoPtr)fct->GetPartInfo(ev);
  506.                         UtilSetControlValue(lfip->fListCtl, newValue);
  507.                         ScrollTo(ev, fct, newValue);
  508.                         }
  509.                     }
  510.                 delete facets;
  511.                 }
  512.             }
  513.         }
  514.     }
  515.  
  516. void ListPart::MyAdjustCtlFacet(Environment* ev, ODFacet* facet)
  517.     {
  518.     WeBeHere("\pListPart::MyAdjustCtlFacet");
  519.  
  520.     CFocus qdPort(ev, facet);
  521.     ListFacetInfoPtr lfip = (ListFacetInfoPtr)facet->GetPartInfo(ev);
  522.     Rect aRect = lfip->fUsedRect;
  523.     short locNbVis = (aRect.bottom-aRect.top-kMargin) / fLineHeight;
  524.     if (facet->GetFrame(ev)->IsRoot(ev))
  525.         {
  526.         aRect.top -= 1;
  527.         aRect.right += 1;
  528.         aRect.bottom -= 14;
  529.         }
  530.     aRect.left = aRect.right - 16;
  531.  
  532.     WindowPtr theWind = facet->GetWindow(ev)->GetPlatformWindow(ev);
  533.     short dh = -theWind->portRect.left;
  534.     short dv = -theWind->portRect.top;
  535.     SetOrigin(0, 0);
  536.     OffsetRect(&aRect, dh, dv);
  537.  
  538.     ControlHandle aCtl = lfip->fListCtl;
  539.     if (!aCtl)
  540.         {
  541.         short theMax = fNbLines-locNbVis+1;
  542.         if (theMax < 1) theMax = 1;
  543.         aCtl = NewControl(facet->GetWindow(ev)->GetPlatformWindow(ev),&aRect,"\p",0,fListIndex,1,theMax,scrollBarProc,0L);
  544.         lfip->fListCtl = aCtl;
  545.         }
  546.     else
  547.         {
  548.         HideControl(aCtl);
  549.         MoveControl(aCtl, aRect.left, aRect.top);
  550.         SizeControl(aCtl, 16, aRect.bottom-aRect.top);
  551.         short theMax = fNbLines-locNbVis+1;
  552.         if (theMax < 1) theMax = 1;
  553.         SetControlMaximum(aCtl, theMax);
  554.         }
  555.     lfip->fNbVis = locNbVis;
  556.     }
  557.  
  558. void ListPart::MyAdjustGWFacet(Environment* ev, ODFacet* facet)
  559.     {
  560.     WeBeHere("\pListPart::MyAdjustGWFacet");
  561.  
  562.     CGrafPtr port;
  563.     GDHandle gdh;
  564.     GWorldPtr newGWorld;
  565.     PixMapHandle pm, npm;
  566.     Rect bounds;
  567.     ListFacetInfoPtr lfip = (ListFacetInfoPtr)facet->GetPartInfo(ev);
  568.     short locNbVis = lfip->fNbVis;
  569.     if (locNbVis > fNbLines) locNbVis = fNbLines;
  570.     ::SetRect(&bounds, 0, 0, fLineWidth, locNbVis * fLineHeight);
  571.  
  572.     CFocus qdPort(ev, facet);
  573.     if (!fGWorld)
  574.         {
  575.         ::GetGWorld(&port, &gdh);
  576.         OSErr err = ::NewGWorld(&newGWorld, fLineDepth, &bounds, nil, nil, useTempMem);
  577. if (err != noErr)
  578.     {
  579. /*
  580.     DebugStr("\pNewGWorld allocation failed in ListPart::MyAdjustGWFacet");
  581. ds("apres NewGWorld");dc();
  582. ds("bounds.left = ");dn(bounds.left);dc();
  583. ds("top = ");dn(bounds.top);dc();
  584. ds("right = ");dn(bounds.right);dc();
  585. ds("bottom = ");dn(bounds.bottom);dpg();
  586. ds("fLineWidth = ");dn(fLineWidth);dc();
  587. ds("locNbVis = ");dn(locNbVis);dc();
  588. ds("fLineHeight = ");dn(fLineHeight);dc();
  589. ds("fLineDepth = ");dn(fLineDepth);dp();
  590. */
  591. return;
  592.     }
  593.         ::SetGWorld(newGWorld, 0L);
  594.         npm = ::GetGWorldPixMap(newGWorld);
  595.         ::LockPixels(npm);
  596.         ::EraseRect(&bounds);
  597.         ::SetGWorld(port, gdh);
  598.         fGWorld = newGWorld;
  599.         fGWNbLines = locNbVis;
  600.         fsomSelf->SetUpGraphics(ev, fGWorld);
  601.         DrawMultCell(ev, facet, fListIndex, fListIndex+fGWNbLines-1);
  602.         }
  603.     else
  604.         {
  605.         if (locNbVis > fGWNbLines)
  606.             {
  607.             ::GetGWorld(&port, &gdh);
  608.             OSErr err = ::NewGWorld(&newGWorld, fLineDepth, &bounds, nil, nil, useTempMem);
  609. if (err != noErr)
  610.     {
  611.     DebugStr("\pNewGWorld reallocation failed in ListPart::MyAdjustGWFacet");
  612.     return;
  613.     }
  614.             ::SetGWorld(newGWorld, 0L);
  615.             pm = ::GetGWorldPixMap(fGWorld);
  616.             npm = ::GetGWorldPixMap(newGWorld);
  617.             ::LockPixels(npm);
  618.             ::EraseRect(&bounds);
  619.             ::CopyBits((BitMapPtr)(*pm), (BitMapPtr)(*npm), &fGWorld->portRect, &fGWorld->portRect, srcCopy, 0L);
  620.             ::SetGWorld(port, gdh);
  621.             port = (CGrafPtr)fGWorld;
  622.             fGWorld = newGWorld;
  623.             fsomSelf->SetUpGraphics(ev, fGWorld);
  624.             ::DisposeGWorld((GWorldPtr)port);
  625.  
  626.             if (fListIndex+locNbVis-1 > fNbLines)
  627.                 {
  628.                 fListIndex = fNbLines-locNbVis+1;
  629.                 UtilSetControlValue(lfip->fListCtl, fListIndex);
  630.                 DrawMultCell(ev, facet, fListIndex, fListIndex+locNbVis-1);
  631.                 }
  632.             else DrawMultCell(ev, facet, fListIndex+fGWNbLines, fListIndex+locNbVis-1);
  633.             fGWNbLines = locNbVis;
  634.             }
  635.         }
  636.     }
  637.  
  638. void ListPart::MyAdjustRectFacet(Environment* ev, Rect* theRect)
  639.     {
  640.     WeBeHere("\pListPart::MyAdjustRectFacet");
  641.     short temp = (theRect->bottom-theRect->top-kMargin) / fLineHeight;
  642.     theRect->bottom = theRect->top + temp * fLineHeight + kMargin;
  643.     }
  644.  
  645. void ListPart::AdjustFacets(Environment* ev, ODFrame* frame)
  646. {
  647.     WeBeHere("\pListPart::AdjustFacets");
  648.     // Given a frame, iterate through all of the facets and adjust them
  649.     // according to the new frame.
  650.  
  651.     ODShape* usedShape  = this->CalcNewUsedShape(ev, frame);
  652.     frame->ChangeUsedShape(ev, usedShape, kODNULL);
  653.     if (usedShape) usedShape->Release(ev);
  654.  
  655.     ODShape* frameShape = frame->AcquireFrameShape(ev, kODNULL);
  656.     ODFrameFacetIterator* facets = frame->CreateFacetIterator(ev);
  657.     for (ODFacet* facet = facets->First(ev);
  658.             facets->IsNotComplete(ev);
  659.             facet = facets->Next(ev) )
  660.     {
  661.         facet->ChangeActiveShape(ev, frameShape, kODNULL);
  662.  
  663.         CFocus foc(ev, facet);
  664.         ODShape*    usedShape = frame->AcquireUsedShape(ev, kODNULL);
  665.         RgnHandle rgn = usedShape->GetQDRegion(ev);
  666.         Rect rct = (*rgn)->rgnBBox;
  667.         usedShape->Release(ev);
  668.         ListFacetInfoPtr lfip = (ListFacetInfoPtr)facet->GetPartInfo(ev);
  669.         lfip->fUsedRect = rct;
  670.         MyAdjustCtlFacet(ev, facet);
  671.         MyAdjustGWFacet(ev, facet);
  672.     }
  673.     delete facets;
  674.     frameShape->Release(ev);
  675. }
  676.  
  677. void ListPart::DrawMultCell(Environment* ev, ODFacet* facet, short firstLine, short lastLine)
  678.     {
  679.     for (short i=firstLine; i<=lastLine; i++) DrawCell(ev, facet, i);
  680.     }
  681.  
  682. void ListPart::DrawCell(Environment* ev, ODFacet* facet, short theLine)
  683.     {
  684.     Rect cbounds;
  685.     short hil;
  686.     CGrafPtr port;
  687.     GDHandle gdh;
  688.  
  689.     if (!fGWorld) return;
  690.  
  691.     ::GetGWorld(&port, &gdh);
  692.     ::SetGWorld(fGWorld, 0);
  693.     cbounds = fGWorld->portRect;
  694.     cbounds.top += fLineHeight * (theLine - fListIndex);
  695.     cbounds.bottom = cbounds.top + fLineHeight;
  696.  
  697.     if ((theLine < 1) || (theLine > fNbLines)) ::EraseRect(&cbounds);
  698.     else
  699.         {
  700.         hil = false;
  701.         if (((fKind == kActive) || (fKind == kPassive)) && (fSel == theLine)) hil = true;
  702.         if ((fKind == kMultiple) && (fMul[theLine-1])) hil = true;
  703.         if (hil) fsomSelf->FillHilCell(ev, theLine, &cbounds); else fsomSelf->FillCell(ev, theLine, &cbounds);
  704.         }
  705.     ::SetGWorld(port, gdh);
  706.     }
  707.  
  708. void ListPart::CopyFromGWorld(Environment* ev, ODFacet* facet)
  709.     {
  710.     WeBeHere("\pListPart::CopyFromGWorld");
  711.  
  712.     if (!fGWorld) return;
  713.  
  714.     CFocus foc(ev, facet);
  715.     ListFacetInfoPtr lfip = (ListFacetInfoPtr)facet->GetPartInfo(ev);
  716.     Rect cbounds, fbounds, rct = lfip->fUsedRect;
  717.  
  718.     short curCtlValue = ::GetControlValue(lfip->fListCtl);
  719.     short locNbVis = lfip->fNbVis;
  720.     if (locNbVis > fNbLines) locNbVis = fNbLines;
  721.     cbounds.top = fLineHeight * (curCtlValue - fListIndex);
  722.     cbounds.left = 0;
  723.     fbounds.left = fbounds.top = 3;
  724.     cbounds.bottom = cbounds.top + fLineHeight * locNbVis;
  725.     fbounds.bottom = fLineHeight * locNbVis + 3;
  726.     fbounds.right = rct.right - 18;
  727.     cbounds.right = fbounds.right - 3;
  728.     if (cbounds.right > fGWorld->portRect.right)
  729.         {
  730.         cbounds.right = fGWorld->portRect.right;
  731.         fbounds.right = cbounds.right + 3;
  732.         }
  733.     ::CopyBits((BitMapPtr)(*(GetGWorldPixMap(fGWorld))), &(((GrafPtr)(facet->GetWindow(ev)->GetPlatformWindow(ev)))->portBits), &cbounds, &fbounds, srcCopy, nil);    
  734.     }
  735.  
  736. void ListPart::NewSel(Environment* ev, ODFacet* facet, short whereto, short wherefrom, char tosel)
  737.     {
  738.     short i, j, k;
  739.     
  740.     if (whereto > fNbLines) return;
  741.     if (fKind == kPassive) fsomSelf->SetSel(ev, facet, whereto);
  742.     if (fKind == kMultiple)
  743.         {
  744.         if (whereto > wherefrom) {i=wherefrom; j=whereto;} else {i=whereto; j=wherefrom;}
  745.         for(k=i; k<=j; k++)
  746.             if (fMul[k-1] != tosel)
  747.                 {
  748.                 fMul[k-1] = tosel;
  749.                 if ((k >= fListIndex) && (k < fListIndex+fGWNbLines)) DrawCell(ev, facet, k);
  750.                 SetDirty(ev);
  751.                 }
  752.         }
  753.     }
  754.  
  755. void ListPart::CloseCellOpened(Environment* ev)
  756.     {
  757.     ODSession* session = ODGetSession(ev, fSelf);
  758.     session->GetDispatcher(ev)->UnregisterIdle(ev, fSelf, fOpenedFacet->GetFrame(ev));
  759.     fsomSelf->CloseOpenedCell(ev, fOpenedFacet);
  760.     DrawCell(ev, fOpenedFacet, fSel);
  761.     CopyFromGWorld(ev, fOpenedFacet);
  762.             {
  763.             CListIterator fiter(fDisplayFrames);
  764.             for ( CFrameProxy* proxy = (CFrameProxy*) fiter.First();
  765.                     fiter.IsNotComplete(); proxy = (CFrameProxy*) fiter.Next() )
  766.                 {
  767.                 ODFrameFacetIterator* facets = proxy->GetFrame(ev)->CreateFacetIterator(ev);
  768.                 for (ODFacet* fct = facets->First(ev);
  769.                         facets->IsNotComplete(ev);
  770.                         fct = facets->Next(ev) )
  771.                     {
  772.                     if (fct != fOpenedFacet)
  773.                         {
  774.                         CFocus lfoc(ev, fct);
  775.                         CopyFromGWorld(ev, fct);
  776.                         }
  777.                     }
  778.                 delete facets;
  779.                 }
  780.             }
  781.     fLineOpened = 0;
  782.     fOpenedFacet = kODNULL;
  783.     SetDirty(ev);
  784.     }
  785.  
  786. void ListPart::ScrollTo(Environment* ev, ODFacet* facet, short whereto)
  787.     {
  788.     short newListIndex;
  789.     short x;
  790.     Rect fromBounds, toBounds;
  791.  
  792.     if (!fGWorld) return;
  793.     
  794.     if (whereto > fNbLines) return;
  795.     newListIndex = (whereto>(fNbLines-fGWNbLines+1))?(fNbLines-fGWNbLines+1):whereto;
  796.     if ((newListIndex+fGWNbLines-1 < fListIndex) || (newListIndex > fListIndex+fGWNbLines-1))
  797.         {
  798.         fListIndex = newListIndex;
  799.         DrawMultCell(ev, facet, newListIndex, newListIndex+fGWNbLines-1);
  800.         }
  801.     else
  802.         {
  803.         if (newListIndex < fListIndex)
  804.             {
  805.             x = fListIndex - newListIndex;
  806.             fromBounds = toBounds = fGWorld->portRect;
  807.             fromBounds.bottom = (fGWNbLines-x) * fLineHeight;
  808.             toBounds.top = x * fLineHeight;
  809.             ::CopyBits((BitMapPtr)(*(GetGWorldPixMap(fGWorld))), (BitMapPtr)(*(GetGWorldPixMap(fGWorld))), &fromBounds, &toBounds, srcCopy, nil);    
  810.             fListIndex = newListIndex;
  811.             DrawMultCell(ev, facet, newListIndex, newListIndex+x-1);
  812.             }
  813.         if (newListIndex > fListIndex)
  814.             {
  815.             x = newListIndex - fListIndex;
  816.             fromBounds = toBounds = fGWorld->portRect;
  817.             fromBounds.top = x * fLineHeight;
  818.             toBounds.bottom = (fGWNbLines-x) * fLineHeight;
  819.             ::CopyBits((BitMapPtr)(*(GetGWorldPixMap(fGWorld))), (BitMapPtr)(*(GetGWorldPixMap(fGWorld))), &fromBounds, &toBounds, srcCopy, nil);    
  820.             fListIndex = newListIndex;
  821.             DrawMultCell(ev, facet, newListIndex+fGWNbLines-x, newListIndex+fGWNbLines-1);
  822.             }
  823.         }
  824.     CopyFromGWorld(ev, facet);
  825.     SetDirty(ev);
  826.     }
  827.  
  828. short ListPart::FirstClick(Environment* ev, ODFacet* facet, ODEventData* event, short* where, char* val, Point macPoint)
  829.     {
  830.     short idx, i;
  831.     char *ps;
  832.     ListFacetInfoPtr lfip = (ListFacetInfoPtr)facet->GetPartInfo(ev);
  833.     ControlHandle aCtl = lfip->fListCtl;
  834. /*
  835.     ODWindow* odwnd = facet->GetFrame(ev)->AcquireWindow(ev);
  836.     ODPoint facetPoint;
  837.     GetWindowPoint(odwnd, ev, event->where, &facetPoint);
  838.     ODTransform* transform = facet->AcquireWindowContentTransform(ev, kODNULL);
  839.     transform->InvertPoint(ev, &facetPoint);
  840.     transform->Release(ev);
  841.     odwnd->Release(ev);
  842. */
  843.     CFocus foc(ev, facet);
  844. //    Point macPoint = facetPoint.AsQDPoint();
  845.     Rect rct = lfip->fUsedRect;
  846.     idx = ((macPoint.v - rct.top - 3 - 1) / fLineHeight) + ::GetControlValue(aCtl);
  847.  
  848.     if (fKind == kActive) if (fLineOpened && (idx != fSel)) CloseCellOpened(ev);
  849.  
  850.     if (fKind != kActive)
  851.         {
  852.         fDoubleClickedLine = -1;
  853.         if (idx == fLastClickedLine)
  854.             if (event->when - fLastClickTime < ::GetDblTime()) fDoubleClickedLine = idx;
  855.         fLastClickedLine = idx;
  856.         fLastClickTime = event->when;
  857.         if (fDoubleClickedLine != -1)
  858.             {
  859.             fsomSelf->GotDoubleClick(ev, facet, fDoubleClickedLine);
  860.             return(false);
  861.             }
  862.         }
  863.  
  864.     if (ClickWithMod(ev, facet, event)) return(false);
  865.     if (idx > fNbLines) return(false);
  866.     if ((fKind == kActive) || (fKind == kPassive))
  867.         if (idx != fSel)
  868.             {
  869.             fsomSelf->SetSel(ev, facet, idx);
  870.             gTempoVal = 1;
  871.             CopyFromGWorld(ev, facet);
  872.             }
  873.     if (fKind == kActive)
  874.         {
  875.         ODSession* session = ODGetSession(ev, fSelf);
  876.         fLineOpened = 1;
  877.         fOpenedFacet = facet;
  878.         rct.top = rct.top + 3 + fLineHeight * (idx - ::GetControlValue(aCtl));
  879.         rct.bottom = rct.top + fLineHeight;
  880.         rct.right -= 18;
  881.         session->GetDispatcher(ev)->RegisterIdle(ev, fSelf, facet->GetFrame(ev), 4);
  882.         fsomSelf->ClickInActive(ev, facet, event, &rct);
  883.         return(false);
  884.         }
  885.     if (fKind == kMultiple)
  886.         {
  887.         if ((event->modifiers & shiftKey) && (fSel != -1))
  888.             {
  889.             *val = fMul[fSel-1];
  890.             ps = (idx > fSel)?(&fMul[fSel-1]):(&fMul[idx-1]);
  891.             for (i=0; i<=mabs(fSel-idx); i++) *ps++ = *val;
  892.             DrawMultCell(ev, facet, fListIndex, fListIndex+fGWNbLines-1);
  893.             }
  894.         else
  895.             {
  896.             *val = !fMul[idx-1];
  897.             fMul[idx-1] = *val;
  898.             DrawCell(ev, facet, idx);
  899.             }
  900.         gTempoVal = 1;
  901.         CopyFromGWorld(ev, facet);
  902.         fSel = idx;
  903.         }
  904.     *where = idx;
  905.     return(true);
  906.     }
  907.  
  908. void ListPart::StillClick(Environment* ev, ODFacet* facet, short where, char val)
  909.     {
  910.     Point localPt;
  911.     short idx, whereto, j;
  912.     ListFacetInfoPtr lfip = (ListFacetInfoPtr)facet->GetPartInfo(ev);
  913.     ControlHandle aCtl = lfip->fListCtl;
  914.     short locNbVis = lfip->fNbVis;
  915.     short curCtlValue = ::GetControlValue(aCtl);
  916.  
  917.     CFocus foc(ev, facet);
  918.     Rect rct = lfip->fUsedRect;
  919.     
  920.     GetMouse(&localPt);
  921.     idx = ((localPt.v - rct.top - 3 - 1) / fLineHeight) + 1;
  922.     if (localPt.v < rct.top + 3) idx -= 1;
  923.     if ((idx >= 1) && (idx <= locNbVis))
  924.         {
  925.         whereto = idx + curCtlValue - 1;
  926.         if (whereto > fNbLines) whereto = fNbLines;
  927.         j = 0;
  928.         if (fKind == kPassive) j = (whereto != fSel);
  929.         if (fKind == kMultiple) j = (fMul[whereto-1] != val);
  930.         if ((fKind != kActive) && (j != 0))
  931.             {
  932.             NewSel(ev, facet, whereto, where, val);
  933.             CopyFromGWorld(ev, facet);
  934.             gTempoVal = 1;
  935.             }
  936.         }
  937.     else if (fKind != kActive)
  938.         {
  939.         short curCtlMax = ::GetControlMaximum(aCtl);
  940.         j = (idx <= 0)?(idx+curCtlValue-1):(idx+curCtlValue-locNbVis);
  941.         whereto = idx+curCtlValue-1;
  942.         j = (j<1)?1:j;
  943.         j = (j>curCtlMax)?curCtlMax:j;
  944.         whereto = (whereto < 1)?1:whereto;
  945.         whereto = (whereto > fNbLines)?fNbLines:whereto;
  946.         NewSel(ev, facet, whereto, where, val);
  947.         if (j != curCtlValue)
  948.             {
  949.             UtilSetControlValue(aCtl, j);
  950.             ScrollTo(ev, facet, ::GetControlValue(aCtl));
  951.             }
  952.         else CopyFromGWorld(ev, facet);
  953.         gTempoVal = 1;
  954.         }
  955.     if (fKind == kMultiple) fSel = whereto;
  956.     }
  957.  
  958. short ListPart::ClickWithMod(Environment* ev, ODFacet* facet, ODEventData* event)
  959.     {
  960.     char *ps, val;
  961.     short i;
  962.     ListFacetInfoPtr lfip = (ListFacetInfoPtr)facet->GetPartInfo(ev);
  963.     ControlHandle aCtl = lfip->fListCtl;
  964.  
  965.     if (fKind == kMultiple)
  966.         {
  967.         ps = fMul;
  968.         if (event->modifiers & optionKey)
  969.             {
  970.             val = (event->modifiers & shiftKey)?1:0;
  971.             for (i=0; i<=fNbLines-1; i++) *ps++ = val;
  972.             DrawMultCell(ev, facet, fListIndex, fListIndex+fGWNbLines-1);
  973.             CopyFromGWorld(ev, facet);
  974.             gTempoVal = 1;
  975.             return(true);
  976.             }
  977.         if (event->modifiers & cmdKey)
  978.             {
  979.             i = 0;
  980.             while (!(*ps++)) i++;
  981.             i = (i >= fNbLines)?0:(i-1);
  982.             UtilSetControlValue(aCtl, i+1);
  983.             ScrollTo(ev, facet, ::GetControlValue(aCtl));
  984.             gTempoVal = 1;
  985.             return(true);
  986.             }
  987.         }
  988.     if ((fKind == kPassive) || (fKind == kActive))
  989.         if (event->modifiers & cmdKey)
  990.             {
  991.             if (fKind == kActive) if (fLineOpened) CloseCellOpened(ev);
  992.             UtilSetControlValue(aCtl, fSel-1);
  993.             ScrollTo(ev, facet, ::GetControlValue(aCtl));
  994.             gTempoVal = 1;
  995.             return(true);
  996.             }
  997.     return(false);
  998.     }
  999.  
  1000. short ListPart::KeyInList(Environment* ev, char theChar)
  1001.     {
  1002.     short where, val, didGetKey = 1;
  1003.     CFocus lfoc(ev, fFocusedFacet);
  1004.     ListFacetInfoPtr lfip = (ListFacetInfoPtr)fFocusedFacet->GetPartInfo(ev);
  1005.     ControlHandle aCtl = lfip->fListCtl;
  1006.     short locNbVis = lfip->fNbVis;
  1007.     val = ::GetControlValue(aCtl);
  1008.     switch (theChar)
  1009.         {
  1010.         case  1:    /* Home */
  1011.             where = 1;
  1012.             break;
  1013.         case  4:    /* End */
  1014.             where = ::GetControlMaximum(aCtl);
  1015.             break;
  1016.         case 11:    /* PageUp */
  1017.             where = val - locNbVis + 1;
  1018.             break;
  1019.         case 12:    /* PageDown */
  1020.             where = val + locNbVis - 1;
  1021.             break;
  1022.         case 30:    /* LineUp */
  1023.             where = val - 1;
  1024.             break;
  1025.         case 31:    /* LineDown */
  1026.             where = val + 1;
  1027.             break;
  1028.         default:
  1029.             if (fWantKey) where = fsomSelf->KeyShortCut(ev, theChar); else didGetKey = 0;
  1030.             break;
  1031.         }
  1032.     if (didGetKey == 0) return(false);
  1033.  
  1034.     UtilSetControlValue(aCtl, where);
  1035.     where = ::GetControlValue(aCtl);
  1036.  
  1037.     if (val != where)
  1038.         {
  1039.         CListIterator fiter(fDisplayFrames);
  1040.         for ( CFrameProxy* proxy = (CFrameProxy*) fiter.First();
  1041.                 fiter.IsNotComplete(); proxy = (CFrameProxy*) fiter.Next() )
  1042.             {
  1043.             ODFrameFacetIterator* facets = proxy->GetFrame(ev)->CreateFacetIterator(ev);
  1044.             for (ODFacet* fct = facets->First(ev);
  1045.                     facets->IsNotComplete(ev);
  1046.                     fct = facets->Next(ev) )
  1047.                 {
  1048.                 CFocus lfoc(ev, fct);
  1049.                 ListFacetInfoPtr lfip = (ListFacetInfoPtr)fct->GetPartInfo(ev);
  1050.                 UtilSetControlValue(lfip->fListCtl, where);
  1051.                 ScrollTo(ev, fct, where);
  1052.                 }
  1053.             delete facets;
  1054.             }
  1055.         }
  1056.     return(true);
  1057.     }
  1058.  
  1059. #define SUSV(prop,kind,len,addr) {                                            \
  1060.     ODSUForceFocus(ev, storageUnit, (prop), (kind));                        \
  1061.     ODULong    oldSize = storageUnit->GetSize(ev);                                \
  1062.     StorageUnitSetValue(storageUnit, ev, (len), (addr));                    \
  1063.     ODULong newSize = storageUnit->GetOffset(ev);                            \
  1064.     if (newSize < oldSize) storageUnit->DeleteValue(ev, oldSize - newSize); }
  1065.  
  1066. void ListPart::ExternalizeListParams(Environment* ev, ODStorageUnit* storageUnit)
  1067.     {
  1068.     WeBeHere("\pListPart::ExternalizeListParams");
  1069.     
  1070.     SUSV(kODPropListListIndex,    kListShort, sizeof(short), &fListIndex)
  1071.     SUSV(kODPropListNbLines,    kListShort, sizeof(short), &fNbLines)
  1072.     SUSV(kODPropListLineHeight,    kListShort, sizeof(short), &fLineHeight)
  1073.     SUSV(kODPropListLineWidth,    kListShort, sizeof(short), &fLineWidth)
  1074.     SUSV(kODPropListLineDepth,    kListShort, sizeof(short), &fLineDepth)
  1075.     SUSV(kODPropListAutoThumb,    kListShort, sizeof(short), &fAutoThumb)
  1076.     SUSV(kODPropListWantKey,    kListShort, sizeof(short), &fWantKey)
  1077.     SUSV(kODPropListKind,        kListShort, sizeof(short), &fKind)
  1078.     SUSV(kODPropListSel,        kListShort, sizeof(short), &fSel)
  1079.     if (fKind != kMultiple)
  1080.         {
  1081.         char dummy = 0;
  1082.         SUSV(kODPropListMul, kListChars, 1, &dummy)
  1083.         }
  1084.     else
  1085.         SUSV(kODPropListMul, kListChars, fNbLines, fMul)
  1086.  
  1087.     fsomSelf->ExternalizeListData(ev, storageUnit);
  1088.     }
  1089.  
  1090. #define SUGV(prop,kind,len,addr,msg) {                                        \
  1091.     if (ODSUExistsThenFocus(ev, storageUnit, (prop), (kind)))                \
  1092.         if ((theSize = storageUnit->GetSize(ev)) != len) DebugStr((msg));    \
  1093.         else StorageUnitGetValue(storageUnit, ev, (len), (addr));            }
  1094.  
  1095. void ListPart::InternalizeListParams(Environment* ev, ODStorageUnit* storageUnit)
  1096.     {
  1097.     WeBeHere("\pListPart::InternalizeListParams");
  1098.     long theSize;
  1099.  
  1100.     SUGV(kODPropListListIndex,    kListShort, sizeof(short), &fListIndex,    "\pStorage size for ListIndex is wrong !")
  1101.     SUGV(kODPropListNbLines,    kListShort, sizeof(short), &fNbLines,    "\pStorage size for NbLines is wrong !")
  1102.     SUGV(kODPropListLineHeight,    kListShort, sizeof(short), &fLineHeight,"\pStorage size for LineHeight is wrong !")
  1103.     SUGV(kODPropListLineWidth,    kListShort, sizeof(short), &fLineWidth,    "\pStorage size for LineWidth is wrong !")
  1104.     SUGV(kODPropListLineDepth,    kListShort, sizeof(short), &fLineDepth,    "\pStorage size for LineDepth is wrong !")
  1105.     SUGV(kODPropListAutoThumb,    kListShort, sizeof(short), &fAutoThumb,    "\pStorage size for AutoThumb is wrong !")
  1106.     SUGV(kODPropListWantKey,    kListShort, sizeof(short), &fWantKey,    "\pStorage size for WantKey is wrong !")
  1107.     SUGV(kODPropListKind,        kListShort, sizeof(short), &fKind,        "\pStorage size for Kind is wrong !")
  1108.     SUGV(kODPropListSel,        kListShort, sizeof(short), &fSel,        "\pStorage size for Sel is wrong !")
  1109.     if (fKind == kMultiple)
  1110.         if (ODSUExistsThenFocus(ev, storageUnit, kODPropListMul, kListChars))
  1111.             {
  1112.             if ((theSize = storageUnit->GetSize(ev)) != fNbLines) DebugStr("\pStorage size for Mul is wrong !");
  1113.             else
  1114.                 {
  1115.                 fMul = NewPtr(theSize);
  1116. OSErr err = MemError(); if (!fMul) err = err?err:memFullErr;
  1117. if (err) DebugStr("\punable to alloc fMul in ListPart::InternalizeListParams");
  1118.                 StorageUnitGetValue(storageUnit, ev, theSize, fMul);
  1119.                 }
  1120.             }
  1121.     else fMul = kODNULL;
  1122.  
  1123.     fsomSelf->InternalizeListData(ev, storageUnit);
  1124.     }
  1125.  
  1126. #define APAV(prop,kind) {                                                        \
  1127.     if ( !storageUnit->Exists(ev, (prop), kODNULL, 0) )                            \
  1128.         storageUnit->AddProperty(ev, (prop));                                    \
  1129.     if ( !storageUnit->Exists(ev, (prop), (kind), 0) )                            \
  1130.         {                                                                        \
  1131.         storageUnit->Focus(ev, (prop), kODPosUndefined, kODNULL, 0, kODPosAll);    \
  1132.         storageUnit->AddValue(ev, (kind));                                        \
  1133.         }                                                                        }
  1134.  
  1135. void ListPart::SetUpListParams(Environment* ev, ODStorageUnit* storageUnit)
  1136.     {
  1137.     WeBeHere("\pListPart::SetUpListParams");
  1138.  
  1139.     APAV(kODPropListListIndex,    kListShort)
  1140.     APAV(kODPropListNbLines,    kListShort)
  1141.     APAV(kODPropListLineHeight,    kListShort)
  1142.     APAV(kODPropListLineWidth,    kListShort)
  1143.     APAV(kODPropListLineDepth,    kListShort)
  1144.     APAV(kODPropListAutoThumb,    kListShort)
  1145.     APAV(kODPropListWantKey,    kListShort)
  1146.     APAV(kODPropListKind,        kListShort)
  1147.     APAV(kODPropListSel,        kListShort)
  1148.     APAV(kODPropListMul,        kListChars)
  1149.     
  1150.     fsomSelf->SetUpListData(ev, storageUnit);
  1151.     }
  1152.  
  1153. void ListPart::ShowMe(Environment* ev, ODFacet* facet, short theLine)
  1154.     {
  1155.     ListFacetInfoPtr lfip = (ListFacetInfoPtr)facet->GetPartInfo(ev);
  1156.     short locNbVis = lfip->fNbVis;
  1157.     ControlHandle aCtl = lfip->fListCtl;
  1158.     short curCtlValue = ::GetControlValue(aCtl);
  1159.     if ((theLine >= curCtlValue) && (theLine <= curCtlValue+locNbVis-1)) return;
  1160.     UtilSetControlValue(aCtl, theLine-1);
  1161.     ScrollTo(ev, facet, ::GetControlValue(aCtl));
  1162.     gTempoVal = 1;
  1163.     }
  1164.  
  1165. short ListPart::GetNbLines(Environment* ev)
  1166.     {
  1167.     return fNbLines;
  1168.     }
  1169.  
  1170. short ListPart::GetSel(Environment* ev)
  1171.     {
  1172.     return fSel;
  1173.     }
  1174.  
  1175. void ListPart::SetNbLines(Environment* ev, short newNbLines)
  1176.     {
  1177. /*
  1178.     for (FacetLink *fl = fFacets.First(); fl->Facet(); fl=fl->Next())
  1179.         {
  1180.         CFocus lfoc(ev, fl->Facet());
  1181.         ControlHandle aCtl = fl->ListCtl();
  1182.         short locNbVis = fl->GetNbVis();
  1183.         short theMax = newNbLines - locNbVis + 1;
  1184.         if (theMax < 1) theMax = 1;
  1185.         ::SetControlMaximum(aCtl, theMax);
  1186.         if (fKind == kMultiple)
  1187.             {
  1188.             char* newfmul = (char *)NewPtrClear(newNbLines);
  1189. OSErr err = MemError(); if (!newfmul) err = err?err:memFullErr;
  1190. if (err) DebugStr("\punable to realloc fMul in ListPart::ModifyNbLines");
  1191.             BlockMove((Ptr)fMul, (Ptr)newfmul, (newNbLines > fNbLines)?fNbLines:newNbLines);
  1192.             DisposePtr((Ptr)fMul);
  1193.             fMul = newfmul;
  1194.             }
  1195.         if (fListIndex+fGWNbLines-1 > newNbLines)
  1196.             {
  1197.             fListIndex = newNbLines-fGWNbLines+1;
  1198.             DrawMultCell(ev, fl->Facet(), fListIndex, fListIndex+fGWNbLines-1);
  1199.             CopyFromGWorld(ev, fl->Facet());
  1200.             }
  1201.         }
  1202.     fNbLines = newNbLines;
  1203. */
  1204.     }
  1205.  
  1206. void ListPart::SetSel(Environment* ev, ODFacet* facet, short theLine)
  1207.     {
  1208.     short oldfsel;
  1209.  
  1210.     if (theLine != fSel)
  1211.         {
  1212.         oldfsel = fSel;
  1213.         fSel = theLine;
  1214.         if ((oldfsel >= fListIndex) && (oldfsel < fListIndex+fGWNbLines)) DrawCell(ev, facet, oldfsel);
  1215.         if ((fSel >= fListIndex) && (fSel < fListIndex+fGWNbLines)) DrawCell(ev, facet, fSel);
  1216.         SetDirty(ev);
  1217.         }
  1218.     }
  1219.  
  1220. void ListPart::SetUpGraphics(Environment* ev, GWorldPtr theGWorld)
  1221.     {
  1222.     }
  1223.  
  1224. void ListPart::FillCell(Environment* ev, short theLine, Rect* theRect)
  1225.     {
  1226.     ::MoveTo(theRect->left+1, theRect->bottom-3);
  1227.     switch(theLine)
  1228.         {
  1229.         case 1:
  1230.             ::DrawString("\pVirtual Part only !");
  1231.             break;
  1232.         case 2:
  1233.             ::DrawString("\pInherit from it to use it");
  1234.             break;
  1235.         }
  1236.     }
  1237.  
  1238. void ListPart::FillHilCell(Environment* ev, short theLine, Rect* theRect)
  1239.     {
  1240.     fsomSelf->FillCell(ev, theLine, theRect);
  1241.     ::InvertRect(theRect);
  1242.     }
  1243.  
  1244. void ListPart::ClickInActive(Environment* ev, ODFacet* facet, ODEventData* event, Rect* theRect)
  1245.     {
  1246.     }
  1247.  
  1248. void ListPart::CloseOpenedCell(Environment* ev, ODFacet* facet)
  1249.     {
  1250.     }
  1251.  
  1252. void ListPart::IdleOpened(Environment* ev, ODFacet* facet)
  1253.     {
  1254.     }
  1255.  
  1256. short ListPart::KeyInActive(Environment* ev, ODFacet* facet, ODEventData* event)
  1257.     {
  1258.     return(false);
  1259.     }
  1260.  
  1261. short ListPart::KeyShortCut(Environment* ev, char theChar)
  1262.     {
  1263.     return((theChar-' ')*10); // just a test
  1264.     }
  1265.  
  1266. void ListPart::GotDoubleClick(Environment* ev, ODFacet* facet, short theLine)
  1267.     {
  1268.     }
  1269.  
  1270. void ListPart::ExternalizeListData(Environment* ev, ODStorageUnit* storageUnit)
  1271.     {
  1272.     }
  1273.  
  1274. void ListPart::InternalizeListData(Environment* ev, ODStorageUnit* storageUnit)
  1275.     {
  1276.     }
  1277.  
  1278. void ListPart::SetUpListData(Environment* ev, ODStorageUnit* storageUnit)
  1279.     {
  1280.     }
  1281.  
  1282. void ListPart::InitializeListData(Environment* ev,
  1283.         short* pNbLines,short* pLineHeight,short* pLineWidth,short* pLineDepth,short* pKind,
  1284.         short* pAutoThumb,short* pWantKey,short* pListIndex,short* pSel,char** pMul)
  1285.     {
  1286.     WeBeHere("\pListPart::InitializeListData");
  1287.     *pNbLines = 2;
  1288.     *pLineHeight = 18;
  1289.     *pLineWidth = 400;
  1290.     *pLineDepth = 1;
  1291.     *pKind = kNull;
  1292.     *pAutoThumb = 0;
  1293.     *pWantKey = 0;
  1294.     *pListIndex = 1;
  1295.     *pMul = 0L;
  1296.     }
  1297.  
  1298. ODISOStr ListPart::GetTheRealPartKind(Environment* ev)
  1299.     { return kListPartKind; }
  1300.  
  1301. ODSLong ListPart::OverrideBeginUsingLibraryResources(Environment* ev)
  1302.     { return BeginUsingLibraryResources(); }
  1303.  
  1304. void ListPart::OverrideEndUsingLibraryResources(Environment* ev, ODSLong ref)
  1305.     { EndUsingLibraryResources(ref); }
  1306.